<extend file="resource/view/site"/>
<block name="content">
    <ul class="nav nav-tabs" role="tablist">
        <li class="active"><a href="#tab1">微信菜单管理</a></li>
        <li><a href="{{site_url('post')}}">添加菜单</a></li>
    </ul>
    <form action="" method="post">
        <div class="panel panel-default">
            <div class="panel-body">
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th width="80">编号</th>
                        <th>标题</th>
                        <th>创建时间</th>
                        <th>是否生效</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <foreach from="$data" value="$d">
                        <tr>
                            <td>{{$d['id']}}</td>
                            <td>
                                {{$d['title']}}
                            </td>
                            <td>{{date("Y-m-d H:i",$d['createtime'])}}</td>
                            <td>
                                <if value="$d['status']">
                                    <span class="label label-success">已在微信端生效</span>
                                    <else/>
                                    <span class="label label-default">未在微信生效</span>
                                </if>
                            </td>
                            <td>
                                <div class="btn-group" role="group" aria-label="...">
                                    <if value="!$d['status']">
                                        <a class="btn btn-default" href="{{site_url('pushWechat',['id'=>$d['id']])}}">推送到微信端</a>
                                    </if>
                                    <a class="btn btn-default" href="{{site_url('post',['id'=>$d['id']])}}">编辑</a>
                                    <a class="btn btn-default" href="javascript:del({{$d['id']}})">删除</a>
                                </div>
                            </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
            </div>

        </div>
        <button class="btn btn-primary">提交</button>
    </form>
</block>
<style>
    table{
        table-layout: fixed;
    }
</style>
<script>
    require(['util'], function (util) {
        $('.copy').each(function () {
            var This = this;
            util.zclip(This, $(This).attr('url'))
        });
    });

    function del(id) {
        util.confirm('确定删除这个菜单吗?', function () {
            $.get("{{site_url('remove')}}", {id: id}, function (res) {
                if (res.valid) {
                    location.reload(true);
                } else {
                    util.message(res.message, '', 'error');
                }
            }, 'json');
        })
    }
</script>